#!/usr/bin/python
# -*- coding: utf-8 -*-

__all__ = [u'GuiStatusBar']

import sys

from pylot.core import (check_type, check_keys)
from pylot.interfaces import WriterInterface

from _pylot.qtgui.misc import (load_designer_file, create_background_palette)
from _pylot.qtgui.styles.charformats import PYLOT_CHAR_FORMATS, PYLOT_CHAR_FORMAT_STD
from _pylot.qtgui.interfaces.widgetinterface import WidgetInterface

from PyQt4 import QtGui

_GuiTextView, WidgetClass = load_designer_file(u'textview.ui')
class GuiStatusBar(QtGui.QStatusBar, WidgetInterface, WriterInterface):

  def __init__(self, formats=PYLOT_CHAR_FORMATS):
    u"""
    :param formats: a dict of QTextCharFormat
    :type formats: obj:`dict`
    """
    QtGui.QStatusBar.__init__(self)
    WidgetInterface.__init__(self)
    WriterInterface.__init__(self) #it seems but it's not a duplicated line ! 

    # TODO: property
    check_type(u'formats', formats, dict)
    for name, fmt in formats.items() :
      check_type(name, fmt, QtGui.QTextCharFormat)
    check_keys(u'formats', formats, [u'std'])
    self.formats = formats
    pass

  def _write (self, text, style):
    self.showMessage(text)

  def _clear(self):
    self.clearMessage()

if __name__ == u"__main__":
  app = QtGui.QApplication(sys.argv)
  win = QtGui.QMainWindow()

  widget = GuiTextView()
  win.setCentralWidget(widget)
  for tool_bar in widget.tool_bars :
    win.addToolBar(tool_bar)
  for menu in widget.menus :
    win.menu_bar.addMenu(menu)

  if widget.pref :
    widget.pref.show()

  widget.write(u'salut\n', u'title')
  widget.write(u'¡ ça marche ! συγχαρητήρια ! 祝賀 !', u'warn')

  win.show()

  app.exec_()

  import doctest
  doctest.testmod()
